package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.annotation.DataVerification;
import com.ruoyi.system.domain.vo.SysQuarterlyCategoryVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysQuarterlyCategory;
import com.ruoyi.system.service.ISysQuarterlyCategoryService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 季刊类别Controller
 *
 * @author ruoyi
 * @date 2022-03-29
 */
@RestController
@RequestMapping("/system/category")
public class SysQuarterlyCategoryController extends BaseController
{
    @Autowired
    private ISysQuarterlyCategoryService sysQuarterlyCategoryService;

    /**
     * 查询季刊类别列表
     */
    @PreAuthorize("@ss.hasPermi('system:category:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysQuarterlyCategory sysQuarterlyCategory)
    {
        startPage();
        List<SysQuarterlyCategoryVo> list = sysQuarterlyCategoryService.selectSysQuarterlyCategoryList(sysQuarterlyCategory);
        return getDataTable(list);
    }

    /**
     * 导出季刊类别列表
     */
    @PreAuthorize("@ss.hasPermi('system:category:export')")
    @Log(title = "季刊类别", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysQuarterlyCategory sysQuarterlyCategory)
    {
        List<SysQuarterlyCategoryVo> list = sysQuarterlyCategoryService.selectSysQuarterlyCategoryList(sysQuarterlyCategory);
        ExcelUtil<SysQuarterlyCategoryVo> util = new ExcelUtil<SysQuarterlyCategoryVo>(SysQuarterlyCategoryVo.class);
        util.exportExcel(response, list, "季刊类别数据");
    }

    /**
     * 获取季刊类别详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:category:query')")
    @GetMapping(value = "/{categoryId}")
    public AjaxResult getInfo(@PathVariable("categoryId") Long categoryId)
    {
        return AjaxResult.success(sysQuarterlyCategoryService.selectSysQuarterlyCategoryByCategoryId(categoryId));
    }

    /**
     * 新增季刊类别
     */
    @DataVerification(name = "添加季刊类别")
    @PreAuthorize("@ss.hasPermi('system:category:add')")
    @Log(title = "季刊类别", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysQuarterlyCategory sysQuarterlyCategory)
    {
        return toAjax(sysQuarterlyCategoryService.insertSysQuarterlyCategory(sysQuarterlyCategory));
    }

    /**
     * 修改季刊类别
     */
    @DataVerification(name = "修改季刊类别")
    @PreAuthorize("@ss.hasPermi('system:category:edit')")
    @Log(title = "季刊类别", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysQuarterlyCategory sysQuarterlyCategory)
    {
        return toAjax(sysQuarterlyCategoryService.updateSysQuarterlyCategory(sysQuarterlyCategory));
    }

    /**
     * 删除季刊类别
     */
    @PreAuthorize("@ss.hasPermi('system:category:remove')")
    @Log(title = "季刊类别", businessType = BusinessType.DELETE)
	@DeleteMapping("/{categoryIds}")
    public AjaxResult remove(@PathVariable Long[] categoryIds)
    {
        return toAjax(sysQuarterlyCategoryService.deleteSysQuarterlyCategoryByCategoryIds(categoryIds));
    }
}
